package tech.dx.springdb.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tech.dx.springdb.entity.CourseAdviceType;
import tech.dx.springdb.respository.CourseAdviceTypeRepository;
import tech.dx.springdb.service.CourseAdviceTypeService;

import java.util.Optional;

/**
 * @ClassName CourseAdviceTypeServiceImpl
 * @Description TODO
 * @Author daoxuan
 * @Date 2019/4/1 12:20
 * @Version 1.0
 */
@Service
public class CourseAdviceTypeServiceImpl implements CourseAdviceTypeService {
    @Autowired
    private CourseAdviceTypeRepository courseAdviceTypeRepository;
    @Override
    public Optional<CourseAdviceType> getById(long id) {
        Optional<CourseAdviceType> byId = courseAdviceTypeRepository.findById(id);
        return byId;
    }

    @Override
    public CourseAdviceType add(CourseAdviceType adviceType) {
        return courseAdviceTypeRepository.save(adviceType);
    }

    @Override
    public CourseAdviceType update(CourseAdviceType adviceType) {
        return courseAdviceTypeRepository.save(adviceType);
    }

    @Override
    public void del(long id) {
        if (getById(id).isPresent())
            courseAdviceTypeRepository.delete(getById(id).get());
    }

    @Override
    public boolean isExitById(long id) {
        return getById(id).isPresent()?true:false;
    }
}
